<template>
    <view-box v-if="addBasic" style="background:#F3F6F7;">
      <div style="height:10px;"></div>
      <div class="border-inten">
        <x-input title="期望行业" v-model="addBasic.desired_industry"  placeholder="期望行业" ></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="期望职业" v-model="addBasic.desired_career"  placeholder="请输入期望职业" ></x-input>
      </div>
      <div style="height:10px;"></div>
      <div class="border-inten">
        <popup-picker title="期望年薪" :data="value6" v-model="addBasic.desired_annual_salary"  value-text-align="right"></popup-picker>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-address title="地址选择" v-model="addBasic.address" raw-value :list="addressData" @on-shadow-change="onShadowChange" value-text-align="right" ></x-address>
      </div>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <group style="width:92%;margin-left:4%;">
            <x-button style="background:#32B6C6;color:#fff;" @click.native="saveup()">确定</x-button>
        </group>
    </view-box>
</template>
<script>
import { ViewBox, Box, XInput, Group, XButton, Datetime, PopupPicker, ChinaAddressData, XHeader, XAddress, CheckIcon } from 'vux'
export default {
  components: {
    ViewBox,
    Box,
    XInput,
    Group,
    XButton,
    Datetime,
    PopupPicker,
    XHeader,
    XAddress,
    CheckIcon
  },
  data () {
    return {
      addressData: ChinaAddressData,
      radio001: ['是否统招'],
      value4: '',
      value3: '',
      value6: [['薪资面议', '1万-2万', '3万-5万', '5万-7万', '7万-10万', '10万-15万', '15万-20万', '200万-25万', '25万-30万', '30万-50万', '50万-100万']],
      addressValue: [],
      annual_salary: [],
      typec: [],
      value1: '',
      value12: [['在职，暂无跳槽打算', '在职，急寻新工作', '离职，正在找工作', '在职，看看新机会']],
      is_unified: false,
      pid: '',
      id: '',
      tabldata: {
        id: '',
        company: '',
        industry: '',
        job_title: '',
        start_time: '',
        over_time: ''
      },
      addBasic: {},
      addiss: {},
      data: [],
      addpid: '',
      demo2: false,
      demo1: true
    }
  },
  computed: {
    disabled () {
    },
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  mounted () {
    this._getconm()
    this._getresume()
    if (!this.$store.state.auth.userInfo) {
      this.$store.dispatch('getUserInfo')
    }
  },
  created () {
    if (this.$route.query.id !== null) {
      this.id = parseInt(this.$route.query.id)
    }
  },
  methods: {
    _getresume () {
      this.$http.get('/resume').then(response => {
        this.addpid = response.data.id
        if (this.$route.query.id > 0) {
          let item = response.data.intention
          let obj = {
            pid: item.pid,
            uid: item.uid,
            desired_industry: item.desired_industry,
            desired_career: item.desired_career,
            desired_annual_salary: [item.desired_annual_salary],
            address: [item.province, item.city, item.area]
          }
          this.data.push(obj)
          this.addBasic = this.data[0]
        }
        // console.log(this.addressValue)
      }).catch(error => {
        console.log(error)
      })
    },
    change () {
      console.log('zhou')
    },
    saveup () {
      if (this.$route.query.id > 0) {
        this.updata()
      } else {
        this.save()
      }
    },
    save () {
      if (this.addBasic.desired_industry === undefined) {
        this.$vux.toast.show({
          text: '请填写消息',
          type: 'text'
        })
        return false
      }
      let data = {
        uid: this.userInfo.id ? this.userInfo.id : 0,
        pid: this.addpid,
        desired_industry: this.addBasic.desired_industry,
        desired_career: this.addBasic.desired_career,
        desired_annual_salary: String(this.addBasic.desired_annual_salary),
        province: this.addiss.province,
        city: this.addiss.city,
        area: this.addiss.area
      }
      this.$http.post('/resume/storeIntention', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    updata () {
      let data = {
        id: this.$route.query.id,
        desired_industry: this.addBasic.desired_industry,
        desired_career: this.addBasic.desired_career,
        desired_annual_salary: String(this.addBasic.desired_annual_salary),
        province: this.addiss.province,
        city: this.addiss.city,
        area: this.addiss.area
      }
      this.$http.put('/resume/updateIntention', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    setDefaults () {
      console.log(1)
    },
    _getconm () {
      this.$http.post('/entrance').then(response => {
        this.pid = response.data.data.id
      })
    },
    onShadowChange (ids, names) {
      this.addiss = {
        province: names[0],
        city: names[1],
        area: names[2]
      }
    }
  }
}
</script>

<style scoped>
    .btn-set-default {
        flex: 1;
        line-height: 50px;
        
    }
    .border-inten{
      width:92%;
      margin-left: 4%;
      border-radius: 7px;
      background:#fff;
    }
</style>
<style>
 .weui-cells:before{
        border-top: 0px solid #D9D9D9 !important;
    }
    .weui-cells:after{
        border-bottom: 0px solid #D9D9D9 !important;
    }
</style>
